package org.piaohao.common;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import java.io.File;
import org.piaohao.controller.AdminController;
import org.piaohao.controller.CaptchaController;
import org.piaohao.controller.DepController;
import org.piaohao.controller.DocController;
import org.piaohao.controller.DriverController;
import org.piaohao.controller.EmpController;
import org.piaohao.controller.LineController;
import org.piaohao.controller.LogController;
import org.piaohao.controller.MainController;
import org.piaohao.controller.OrgController;
import org.piaohao.controller.OrgTreeController;
import org.piaohao.controller.PolicyController;
import org.piaohao.controller.PosController;
import org.piaohao.controller.RuleController;
import org.piaohao.controller.StatisticController;
import org.piaohao.controller.UserController;
import org.piaohao.controller.VehicleController;
import org.piaohao.controller.WarnController;
import org.piaohao.interceptor.GlobalInterceptor;
import org.piaohao.interceptor.LogInterceptor;
import org.piaohao.model.DepOrgTree;
import org.piaohao.model.Department;
import org.piaohao.model.DocAcc;
import org.piaohao.model.Document;
import org.piaohao.model.Driver;
import org.piaohao.model.DriverLicense;
import org.piaohao.model.Employee;
import org.piaohao.model.EmployeedLicense;
import org.piaohao.model.Line;
import org.piaohao.model.Log;
import org.piaohao.model.OrgOrgTree;
import org.piaohao.model.OrgTree;
import org.piaohao.model.Organization;
import org.piaohao.model.Policy;
import org.piaohao.model.PosOrgTree;
import org.piaohao.model.Position;
import org.piaohao.model.Rule;
import org.piaohao.model.User;
import org.piaohao.model.Vehicle;
import org.piaohao.model.Warn;
import org.piaohao.model.WarnEmp;
import org.piaohao.model.WarnResult;

/**
 * Created on : 2013-5-4, 15:09:07
 *
 * @author piaohao
 */
public class GlobalConfig extends JFinalConfig {

    /**
     * 配置常量
     */
    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true);
        me.setViewType(ViewType.JSP); // 设置视图类型为Jsp，否则默认为FreeMarker
    }

    /**
     * 配置路由
     */
    @Override
    public void configRoute(Routes me) {
        me.add("/main", MainController.class);
        me.add("/captcha", CaptchaController.class);
        me.add("/driver", DriverController.class);
        me.add("/org", OrgController.class);
        me.add("/dep", DepController.class);
        me.add("/vehicle", VehicleController.class);
        me.add("/line", LineController.class);
        me.add("/warn", WarnController.class);
        me.add("/pos", PosController.class);
        me.add("/emp", EmpController.class);
        me.add("/statistic", StatisticController.class);
        me.add("/orgtree", OrgTreeController.class);
        me.add("/policy", PolicyController.class);
        me.add("/doc", DocController.class);
        me.add("/rule", RuleController.class);
        me.add("/log", LogController.class);
        me.add("/admin", AdminController.class);
        me.add("/user", UserController.class);
    }

    /**
     * 配置插件
     */
    @Override
    public void configPlugin(Plugins me) {
        // 配置C3p0数据库连接池插件
        C3p0Plugin c3p0Plugin = new C3p0Plugin(new File(PathKit.getRootClassPath() + "/C3P0.properties"));
        me.add(c3p0Plugin);

        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
        me.add(arp);
        arp.addMapping("t_department", Department.class);
        arp.addMapping("t_driver", Driver.class);
        arp.addMapping("t_driver_license", DriverLicense.class);
        arp.addMapping("t_employee", Employee.class);
        arp.addMapping("t_employeed_license", EmployeedLicense.class);
        arp.addMapping("t_line", Line.class);
        arp.addMapping("t_org_tree", OrgTree.class);
        arp.addMapping("t_organization", Organization.class);
        arp.addMapping("t_position", Position.class);
        arp.addMapping("t_user", User.class);
        arp.addMapping("t_vehicle", Vehicle.class);
        arp.addMapping("t_org_org_tree", OrgOrgTree.class);
        arp.addMapping("t_dep_org_tree", DepOrgTree.class);
        arp.addMapping("t_pos_org_tree", PosOrgTree.class);
        arp.addMapping("t_policy", Policy.class);
        arp.addMapping("t_rule", Rule.class);
        arp.addMapping("t_document", Document.class);
        arp.addMapping("t_file", org.piaohao.model.File.class);
        arp.addMapping("t_log", Log.class);
        arp.addMapping("t_warn", Warn.class);
        arp.addMapping("t_warn_emp", WarnEmp.class);
        arp.addMapping("t_warn_result", WarnResult.class);
        arp.addMapping("t_doc_acc", DocAcc.class);
    }

    /**
     * 配置全局拦截器
     */
    @Override
    public void configInterceptor(Interceptors me) {
        me.add(new GlobalInterceptor());
        me.add(new LogInterceptor());
    }

    /**
     * 配置处理器
     */
    @Override
    public void configHandler(Handlers me) {
    }
}
